package com.skillworld.webapp.model.enrollment;

import java.util.Calendar;

import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

import com.skillworld.webapp.model.lesson.Exam;

@Embeddable
public class ReleasedExam
{
    public enum State { PENDING, REQUESTED, ANSWERED, DISAPPROVED, PASSED }
    public enum Grade { VERY_BAD, BAD, SUFFICIENT, GOOD ,VERY_GOOD }
    
    private State state = State.PENDING;
    private Exam exam;
    private String responseFile;
    private String commentary;
    private Grade grade;
    private Calendar releaseDate;
    private Calendar submittedDate;
    private Calendar evaluationDate;


    ReleasedExam()
    {

    }    
    
    ReleasedExam(Exam exam)
    {
        this.state = State.REQUESTED;
        this.exam = exam;
        this.releaseDate = Calendar.getInstance();
    }


    @ManyToOne(optional=true,fetch=FetchType.LAZY)
    @JoinColumn(name="idExam")
    public Exam getExam() 
    {
        return exam;
    }
    
    public void setExam(Exam exam)
    {
        this.exam = exam;
    }
    
    @Enumerated(EnumType.ORDINAL)
    @Column(name="grade")
    public Grade getGrade() 
    {
        return grade;
    }
    
    public void setGrade(Grade grade)
    {
        this.grade = grade;
        if(grade != null)
        {
	        if (grade.ordinal() >= 3)
	        { state = State.PASSED; }
	        else
	        { state = State.DISAPPROVED; }
        }
    }
    
    @Column(name="responseFile")
    public String getResponseFile()
    {
        return responseFile;
    }
    
    protected void setResponseFile(String responseFile)
    {
        this.responseFile = responseFile;
    }   
    
    @Enumerated(EnumType.STRING)
    @Column(name="state")
    public State getState()
    {
        return state;
    }
    
    void setState(State state)
    {
        this.state = state;
    }

    @Column(name="commentary")
    public String getCommentary() 
    {
        return commentary;
    }
    
    void setCommentary(String commentary)
    {
        this.commentary = commentary;
    }
    
    @Column(name="releaseDate")
    public Calendar getReleaseDate() 
    {
        return releaseDate;
    }
    
    void setReleaseDate(Calendar releaseDate)
    {
        this.releaseDate = releaseDate;
    }
    
    @Column(name="submittedDate")
    public Calendar getSubmittedDate() {
        return submittedDate;
    }
    
    void setSubmittedDate(Calendar submittedDate) {
        this.submittedDate = submittedDate;
    }
    
    @Column(name="evaluationDate")
    public Calendar getEvaluationDate() 
    {
        return evaluationDate;
    }
    
    void setEvaluationDate(Calendar evaluationDate)
    {
        this.evaluationDate = evaluationDate;
    }
}
